package oceanwiki.job;

import oceanwiki.service.IEbookSnapshotService;
import oceanwiki.util.SnowFlake;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @FileName EbookSnapshotJob
 * @Description
 * @Author Me
 * @date 2024-09-21
 **/

@Component
public class EbookSnapshotJob {
    private static final Logger LOG = LoggerFactory.getLogger(EbookSnapshotJob.class);

    @Resource
    private IEbookSnapshotService ebookSnapshotService;

    @Autowired
    private SnowFlake snowFlake;

    @Scheduled(cron = "0 0/1 * * * ?")
    public void cron() {
        //增加流水日志号
        MDC.put("LOG_ID", String.valueOf(snowFlake.nextId()));
        LOG.info("生成今日电子书快照开始");
        long start = System.currentTimeMillis();
        ebookSnapshotService.getSnapshot();
        LOG.info("生成快照结束，耗时：{}ms", System.currentTimeMillis()-start);
    }
}
